<template>
    <div class="elm-edit">
        <elm-page-bb class="elm-edit">
            <el-form ref="model" :model="model" size="small" label-width="130px">
                <elm-row>
                    <el-form-item label="合同编号" prop="sys_code_key">
                        <el-input v-model="model.sys_code_key" :disabled="true" placeholder="自动生成无需填写"></el-input>
                    </el-form-item>
                    <el-form-item label="合同名称" prop="contract_name" :rules="[{ required: true, message: '必须填写'}]">
                        <el-input v-model="model.contract_name"></el-input>
                    </el-form-item>
                </elm-row>
                <elm-row>
                    <el-form-item label="合同金额(含税)" prop="amount" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
                        <el-input v-model="model.amount">
                            <template slot="append"><div style="width: 25px;text-align: center;">万元</div></template>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="税率" prop="tax_rate" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
                        <el-input v-model="model.tax_rate">
                            <template slot="append"><div style="width: 25px;text-align: center;">%</div></template>
                        </el-input>
                    </el-form-item>
                </elm-row>
                <elm-row>
                    <el-form-item label="合同金额(不含税)" prop="amount_notax" :rules="[{trigger: 'blur' ,validator: validateNumber}]">
                        <el-input v-model="model.amount_notax">
                            <template slot="append"><div style="width: 25px;text-align: center;">万元</div></template>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="合同类型" prop="contract_type">
                        <elm-code dict_type="cmis_contract_lx" v-model="model.contract_type"></elm-code>
                    </el-form-item>
                </elm-row>
                <elm-row>
                    <el-form-item label="签订日期" prop="contract_date">
                        <el-date-picker v-model="model.contract_date" value-format="yyyy-MM-dd" type="date"
                                        style="width: 100%">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="合同状态" prop="status">
                        <elm-code dict_type="cmis_contract_zt" v-model="model.status"></elm-code>
                    </el-form-item>
                </elm-row>
                <elm-row>
                    <el-form-item label="生效日期" prop="start_date">
                        <el-date-picker v-model="model.start_date" value-format="yyyy-MM-dd" type="date"
                                        style="width: 100%">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="截止日期" prop="end_date">
                        <el-date-picker v-model="model.end_date" value-format="yyyy-MM-dd" type="date"
                                        style="width: 100%">
                        </el-date-picker>
                    </el-form-item>
                </elm-row>
                <elm-row>
                    <el-form-item label="负责人" prop="charge_person">
                        <elm-ei v-model="model.charge_person" disabled></elm-ei>
                    </el-form-item>
                    <el-form-item label="所属部门" prop="org_id">
                        <elm-org v-model="model.org_id"></elm-org>
                    </el-form-item>
                </elm-row>
                <elm-row>
                    <el-form-item label="关联线索" prop="glxs">
                        <elm-select-input v-model="model.glxs" url="/business/my/GetLeadData" :show-id="true"></elm-select-input>
                    </el-form-item>
                    <el-form-item label="关联商机" prop="glsj">
                        <elm-select-input v-model="model.glsj" url="/business/my/GetOppoData" :show-id="true"></elm-select-input>
                    </el-form-item>
                </elm-row>
                <el-form-item label="附件">
                    <elm-upload module_name="biz_cmis_contract_files" :rel_id="model.id" :multiple="false" :limit="10" list-type="file" tip=""></elm-upload>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input type="textarea" v-model="model.remark" :rows="2"></el-input>
                </el-form-item>
            </el-form>
            <el-card style="min-height: 140px;"  shadow="hover">
                <div slot="header">
                    <span>合同双方信息</span>
                </div>
                <el-form ref="model" :model="model" size="small" label-width="100px">
                    <el-form-item label="甲方单位" prop="unit_a">
                        <el-input v-model="model.unit_a"></el-input>
                    </el-form-item>
                    <elm-row>
                        <el-form-item label="联系人(甲)" prop="lxr_xm_a">
                            <el-input v-model="model.lxr_xm_a"></el-input>
                        </el-form-item>
                        <el-form-item label="职务(甲)" prop="lxr_zw_a">
                            <el-input v-model="model.lxr_zw_a"></el-input>
                        </el-form-item>
                    </elm-row>
                    <elm-row>
                        <el-form-item label="电话(甲)" prop="lxr_dh_a">
                            <el-input v-model="model.lxr_dh_a"></el-input>
                        </el-form-item>
                        <el-form-item label="邮箱(甲)" prop="lxr_yx_a">
                            <el-input v-model="model.lxr_yx_a"></el-input>
                        </el-form-item>
                    </elm-row>
                    <el-form-item label="乙方单位" prop="unit_b">
                        <el-input v-model="model.unit_b"></el-input>
                    </el-form-item>
                    <elm-row>
                        <el-form-item label="联系人(乙)" prop="lxr_xm_b">
                            <el-input v-model="model.lxr_xm_b"></el-input>
                        </el-form-item>
                        <el-form-item label="职务(乙)" prop="lxr_zw_b">
                            <el-input v-model="model.lxr_zw_b"></el-input>
                        </el-form-item>
                    </elm-row>
                    <elm-row>
                        <el-form-item label="电话(乙)" prop="lxr_dh_b">
                            <el-input v-model="model.lxr_dh_b"></el-input>
                        </el-form-item>
                        <el-form-item label="邮箱(乙)" prop="lxr_yx_b">
                            <el-input v-model="model.lxr_yx_b"></el-input>
                        </el-form-item>
                    </elm-row>
                </el-form>
            </el-card>
            <template #bottom>
                <el-button type="success" size="small" @click="submit">立即保存</el-button>
                <el-button size="small" @click="close">取消</el-button>
            </template>
        </elm-page-bb>
    </div>
</template>

<script>
export default {
    extends: elmVueBase,
    data() {
        return {
            model: {id: elm.newGuid(),charge_person:null},
        }
    },
    async created() {
      this.model.charge_person= await this.get_user_ei();
    },
    methods: {
        async submit() {
            await this.$refs["model"].validate();
            var res = await elm.post('/business/my/business/UpsertCont', this.model);
            if (res == true) {
                this.close();
                this.v('保存成功。');
                this.request.callVue.tablebinding();
            } else {
                this.error('保存失败，请稍后尝试。');
            }
        },
      async get_user_ei(){
        var res = await elm.post('/system/login/GetUserEi');
        //console.log(res);
        if(res.length>0)
          return res[0].emp_code;
        else
          return "";
      },
    }
}
</script>

<style scoped>

</style>